package com.oa.controller;

import com.oa.pojo.Party;
import com.oa.pojo.Result;
import com.oa.service.PartyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags= "党员接口" )
@RestController
@RequestMapping("/Party")
public class PartyController {
    @Autowired
    private PartyService partyService;
    @CrossOrigin
    @GetMapping("/selectByUserId")
    public Result selectByUserId(Party party){
        List<Party> partyList=partyService.selectByUserId(party);
        return Result.success(partyList);
    }
    @ApiOperation(value="添加党员")
    @CrossOrigin
    @PostMapping("/insert")
    public Result insert(@RequestBody Party party){
        System.out.println("进入添加党员用户信息接口");
        if(partyService.insert(party)==1){
            return Result.success();
        }else{
            return Result.error("该用户已存在");
        }
    }
    @ApiOperation(value = "更新党员信息")
    @CrossOrigin
    @PostMapping("/update")
    public Result update(@RequestBody Party party){
        System.out.println("进入党员信息更新接口");
        int flag= partyService.update(party);
        if(flag==1){
            return Result.success();
        }else{
            return Result.error("该用户不存在");
        }
    }
    @ApiOperation(value = "党员删除接口")
    @CrossOrigin
    @PostMapping("/delete")
    public Result delete(Party party){
        System.out.println("进入党员删除接口");
        int flag=partyService.delete(party);
        if(flag==1){
            return Result.success();
        }else{
            return Result.error("该用户不存在");
        }
    }
}
